# == Class: nrpe
#
# Full description of class nrpe here.
#
# === Parameters
#
# Document parameters here.
#
# [*sample_parameter*]
#   Explanation of what this parameter affects and what it defaults to.
#   e.g. "Specify one or more upstream ntp servers as an array."
#
# === Variables
#
# Here you should define a list of variables that this module would require.
#
# [*sample_variable*]
#   Explanation of how this variable affects the funtion of this class and if
#   it has a default. e.g. "The parameter enc_ntp_servers must be set by the
#   External Node Classifier as a comma separated list of hostnames." (Note,
#   global variables should be avoided in favor of class parameters as
#   of Puppet 2.6.)
#
# === Examples
#
#  class { nrpe:
#    servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
#  }
#
# === Authors
#
# Author Name <author@domain.com>
#
# === Copyright
#
# Copyright 2014 Your name here, unless otherwise noted.
#
class nrpe (
  $enable_cpumonitor = true,
){
 #tag 'nrpeclient',
 case $operatingsystemmajrelease {
    '5': {
          package { 'nagios-nrpe.x86_64':
            ensure => present,
            require  => Yumrepo['site']
          }
          package { 'nagios-plugins.x86_64':
            ensure => present,
            require  => Yumrepo['site']
          }
          package { 'nagios-plugins-nrpe.x86_64':
            ensure => present,
            require  => Yumrepo['site']
          }

          file { "/etc/nagios/nrpe.cfg":
            mode       =>  '0644',
            owner      =>  'root',
            group      =>  'root',
            source     =>  "puppet:///modules/${module_name}/nrpe.cfg",
            require    =>  Package['nagios-nrpe.x86_64'],
            notify     =>  Service['nrpe']
          }
          file { '/usr/bin/timeout':
            owner  => "root",
            group  => "root",
            mode   => '0755',
            source => "puppet:///modules/${module_name}/timeout",
          }
         }
    '6': {
          package { ["nrpe",
			"nagios-plugins-all",
			"tree"]:
            ensure => present,
            require  => Yumrepo['site']
          }
          file { "/etc/nagios/nrpe.cfg":
            mode       =>  '0644',
            owner      =>  'root',
            group      =>  'root',
            source     =>  "puppet:///modules/${module_name}/nrpe.cfg",
            require    =>  Package['nrpe'],
            notify     =>  Service['nrpe']
          }
         }
    /7|8|9/: {
          package { ["nrpe",
                        "ipmitool",
                        "nagios-plugins-all",
                        "tree"]:
            ensure => present,
            require  => Yumrepo['site']
          } ->
          file { "/etc/nagios/nrpe.cfg":
            mode       =>  '0644',
            owner      =>  'root',
            group      =>  'root',
            source     =>  "puppet:///modules/${module_name}/nrpe.cfg",
            require    =>  Package['nrpe'],
            notify     =>  Service['nrpe']
          }
         }
    }
  sudo::conf { 'nrpe':
    priority => 15,
    source => "puppet:///modules/${module_name}/nrpe.sudo",
  } ~>

  service { 'nrpe':
    name       =>  'nrpe',
    ensure     =>  'running',
    enable     =>   true,
    hasstatus  =>   true,
    hasrestart =>   true,
    require    =>   File['/etc/nagios/nrpe.cfg'],
  }->
  #file {"/scratch/testfs":
  #  mode       =>  '0644',
  #  owner      =>  'root',
  #  group      =>  'root',
  #  content    =>  "Test file for nagios. Do not delete",
  #}
  file { "/usr/lib64/nagios/plugins":
    mode       =>  '0755',
    owner      =>  'nrpe',
    group      =>  'nrpe',
    source     =>  "puppet:///modules/${module_name}/nrpe",
    recurse    =>   true,
    ensure     =>   directory,
    force      =>   true,
    require    =>   File['/etc/nagios/nrpe.cfg'],
  }



#######sysstat huqingbao monitor####
  package { ["sysstat"]:
            ensure => present,
            require  => Yumrepo['site']
          }
#  package { ["apptainer-suid"]:
#            ensure => present,
#          }
#  file { "/etc/singularity":
#    ensure  => absent,
#    recurse => true,
#    force   => true,
#  }


  file { "/etc/cron.d/sysstat":
    mode       =>  '0600',
    owner      =>  'root',
    group      =>  'root',
    source     =>  "puppet:///modules/${module_name}/sysstat",
    require    =>   Package['sysstat']
  }

 # file { "/etc/cron.d/monitorplugin.minitely":
 #   mode       =>  '0600',
 #   owner      =>  'root',
 #   group      =>  'root',
 #   source     =>  "puppet:///modules/${module_name}/monitorplugin.minitely",
 #   require    =>   Package['sysstat']
 # }


  file { "/var/log/nodestat":
    mode       =>  '0755',
    owner      =>  'root',
    group      =>  'root',
    #recurse    =>   true,
    ensure     =>   directory,
    #force      =>   true,
    require    =>   Package['sysstat']
  }
########sysstat huqingbao monitor######

  if $enable_cpumonitor  {
    file {"/etc/cron.d/cpumonitor":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/cpumonitor",
    }
  }
   
}
